log using "owenli_log.log", replace

// Replication files for "The Conditional Nature of Publication Bias: The Conditional Nature of Publication Bias: A Meta-Regression Analysis" 
		// by Erica Owen and Quan Li
// Date: 1/6/2019
// File author: Erica Owen (ericaowen@pitt.edu)
// This do file replicates results in main text

// Set working directory


// #0
// program set-up
version 13.1
clear all
macro drop _all
set linesize 80

// Load data
use "owenli_data.dta", clear

// Figure 1 
sum pc_fe  if dvshare==0   & xkey==0
local mean1 `r(mean)' 

sum pc_fe  if dvshare==0   & xkey==1
local mean2 `r(mean)' 

graph twoway 	(scatter precfe pc_fe  if dvshare==0   & xkey==0, msymbol(X) mcolor(red) jitter(7)) ///
	(scatter precfe pc_fe  if dvshare==0  & xkey==1, msymbol(Oh) mcolor(blue) jitter(7)), ///
	 name(fun1, replace) /// 
	 xline(`mean1',   lcolor(red)) ///
	 xline(`mean2',   lpattern(dash) lcolor(blue)) ///
	ytitle("Precision") xtitle("Partial correlation") ///
	title("") xlabel(-.4(.2).3) ylabel(0(10)60) ///
	legend(label(1 "Control") label(2 "Key") pos(11) ring(0))  graphregion(margin(tiny))

	
sum pc_fe  if dvshare==1   & xkey==0
local mean1 `r(mean)' 

sum pc_fe  if dvshare==1  & xkey==1
local mean2 `r(mean)' 

graph twoway 	(scatter precfe pc_fe  if dvshare==1   & xkey==0, msymbol(X) mcolor(red) jitter(7)) ///
	(scatter precfe pc_fe  if dvshare==1  & xkey==1, msymbol(Oh) mcolor(blue) jitter(7)), ///
	 name(fun2, replace) /// 
	 xline(`mean1',   lcolor(red)) ///
	 xline(`mean2',   lpattern(dash) lcolor(blue)) ///
	ytitle("Precision") xtitle("Partial correlation") ///
	title("") xlabel(-.4(.2).4) ylabel(0(10)60) /// 
	legend(label(1 "Control") label(2 "Key") pos(11) ring(0)) graphregion(margin(tiny))


// Table 1

// Models 1-4 
local c if dvshare==0  

reg pc_fe sepcfe   `c' [aweight=prfesq], robust
est sto m1

local se c.sepcfe##i.xkey

reg pc_fe   `se'  `c' [aweight=prfesq], robust
est sto m2

local d  dvlog develop nonpolity   fectry ldv robust gmm sampyr 
local se c.sepcfe##i.xkey
local c if dvshare==0  

reg pc_fe `d' `se'  `c' [aweight=prfesq], robust	
est sto m3


local se c.sepcfe##i.xkey year
local c if dvshare==0  

reg pc_fe   `se'  `c' [aweight=prfesq], robust	
est sto m4




// Models 5-8
local c if dvshare==1  

reg pc_fe sepcfe   `c' [aweight=prfesq], robust
est sto m5

local se c.sepcfe##i.xkey

reg pc_fe   `se'  `c' [aweight=prfesq], robust
est sto m6

local d  dvlog develop nonpolity   fectry ldv robust gmm sampyr 
local se c.sepcfe##i.xkey

local c if dvshare==1  

reg pc_fe `d' `se'  `c' [aweight=prfesq], robust	
est sto m7


local se c.sepcfe##i.xkey year
local c if dvshare==1  

reg pc_fe   `se'  `c' [aweight=prfesq], robust	
est sto m8


local mtitles 1 2 3 4 5 6 7 8 

esttab m1 m2 m3 m4 m5 m6 m7 m8 using "table1.tex",   ///
	b(%9.3f) se(%9.3f) scalars(r2_a) sfmt(%9.2f) label ///
  compress notes nogaps nolines replace star(* 0.1 ** 0.05 *** 0.01) nonumbers ///
  title("Conditional publication bias" \label{tab:pub1}) ///
 mtitles(`mtitles') 
 

// Marginal effects plots and calculations 

// Model 2 
 est restore m2
 margins, dydx(sepcfe) at(xkey=(0 1))
 marginsplot, yline(0, lpattern(dash) lcolor(gray)) name(g1, replace) title("Level (Model 2)") ///
	plotopts(msymbol(O) connect(none)) ytitle("Marginal effect std. error")

// Model 6
 est restore m6
 margins, dydx(sepcfe) at(xkey=(0 1))
 marginsplot,yline(0, lpattern(dash) lcolor(gray)) name(g2, replace) title("Share (Model 6)") ///
	plotopts(msymbol(O) connect(none)) ytitle("")
 
// Model 3
  est restore m3
 margins, dydx(sepcfe) at(xkey=(0 1))
 marginsplot, yline(0, lpattern(dash) lcolor(gray)) name(g3, replace) title("Level (Model 3)") ///
	plotopts(msymbol(O) connect(none)) ytitle("Marginal effect std. error")
 
// Model 7
 est restore m7
 margins, dydx(sepcfe) at(xkey=(0 1))
 marginsplot,yline(0, lpattern(dash) lcolor(gray)) name(g4, replace) title("Share (Model 7)") ///
	plotopts(msymbol(O) connect(none)) ytitle("")
  
// Model 4
 est restore m4
 margins, dydx(sepcfe) at(xkey=(0 1))
 marginsplot, yline(0, lpattern(dash) lcolor(gray)) name(g5, replace) title("Level (Model 4)") ///
	plotopts(msymbol(O) connect(none)) ytitle("Marginal effect std. error")

// Model 8
  est restore m8
 margins, dydx(sepcfe) at(xkey=(0 1))
 marginsplot, yline(0, lpattern(dash) lcolor(gray)) name(g6, replace) title("Share (Model 8)") ///
	plotopts(msymbol(O) connect(none)) ytitle("")
 
 
graph combine g1 g2 g3 g4 g5 g6, name(g8, replace) imargin(small) row(3) note("Note: 95% confidence interval")

// Summary statistics for main variables. Table A1.

local c if dvshare==0   
local x pc_fe sepcfe xkey  
sum `x'   `c'

local c if dvshare==1 
local x pc_fe sepcfe xkey 
sum `x'   `c'

// Tabulation of significance for key and control
tab sig xkey, col


log close


